package com.charonmc.commands;

import com.charonmc.utils.PrefixUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;


public class Rank implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        if (sender instanceof Player){
            Player player = (Player) sender;
            if (args.length != 1){
                //这小子他妈乱用命令
                return true;
            } else {
                if (args[0].length() == 1 && StringUtils.isNumeric(args[0])) {
                    if (sender.hasPermission("Charon.Prefix." + args[0])) {
                        Integer prefix = Integer.valueOf(args[0]);
                        PrefixUtils.setPlayerPrefix(player, prefix);
                    } else {
                        sender.sendMessage("§c您尚未获得该称号");
                    }
                } else if (args[0].equals("-1")){
                    PrefixUtils.setPlayerPrefix(player, -1);
                    //这小子他妈乱用命令
                    return true;
                }
            }
        }
        return true;
    }
}
